/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ControlLayer;
import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;

/**
 *
 * @author AMP
 */
public class CtrProduct
{
	public CtrProduct()
	{
	}

	public Product findByBarcode(String barcode)
    {
        IFDBProduct dbPro = new DBProduct();
        return dbPro.findProduct(barcode, true);
    }

	public int updateProduct(String productType, String barcode, String name, Float purchasePrice, Float salesPrice, Float rentPrice, String countryOfOrigin, int minStock, int maxStock, int currentStock, int supplierID, String variable1, String variable2)
    {
		DBSupplier dbSupplier = new DBSupplier();
		if(productType.equals("Clothing"))
		{
			IFDBClothing dbClo = new DBClothing();
			Clothing clothing = new Clothing();
			clothing.setBarCode(barcode);
			clothing.setName(name);
			clothing.setPurchasePrice(purchasePrice);
			clothing.setSalesPrice(salesPrice);
			clothing.setRentPrice(rentPrice);
			clothing.setCountryOfOrigin(countryOfOrigin);
			clothing.setMinStock(minStock);
			clothing.setMaxStock(maxStock);
			clothing.setCurrentStock(currentStock);
			clothing.setSize(variable1);
			clothing.setColour(variable2);
			clothing.setSupplier(dbSupplier.findSupplier(supplierID, true));
			return dbClo.updateClothing(clothing);
		}
		if(productType.equals("Equipment"))
		{
			IFDBEquipment dbEquip = new DBEquipment();
			Equipment equipment = new Equipment();
			equipment.setBarCode(barcode);
			equipment.setName(name);
			equipment.setPurchasePrice(purchasePrice);
			equipment.setSalesPrice(salesPrice);
			equipment.setRentPrice(rentPrice);
			equipment.setCountryOfOrigin(countryOfOrigin);
			equipment.setMinStock(minStock);
			equipment.setMaxStock(maxStock);
			equipment.setCurrentStock(currentStock);
			equipment.setType(variable1);
			equipment.setDescription(variable2);
			return dbEquip.updateEquipment(equipment);
		}
		if(productType.equals("Gun Replicas"))
		{
			IFDBGunReplicas dbGun = new DBGunReplicas();
			GunReplicas gunRep = new GunReplicas();
			gunRep.setBarCode(barcode);
			gunRep.setName(name);
			gunRep.setPurchasePrice(purchasePrice);
			gunRep.setSalesPrice(salesPrice);
			gunRep.setRentPrice(rentPrice);
			gunRep.setCountryOfOrigin(countryOfOrigin);
			gunRep.setMinStock(minStock);
			gunRep.setMaxStock(maxStock);
			gunRep.setCurrentStock(currentStock);
			gunRep.setFabric(variable1);
			gunRep.setCalibre(variable2);
			return dbGun.updateGunReplica(gunRep);
		}
		else
		{
			return 0;
		}

	}

	public void insertProduct(String productType, String name, Float purchasePrice, Float salesPrice, Float rentPrice, String countryOfOrigin, int minStock, int maxStock, int currentStock, int supplierID, String variable1, String variable2)
	{
		IFDBSupplier dbSup = new DBSupplier();
		if(productType.equals("Clothing"))
		{
			IFDBClothing dbClo = new DBClothing();
			Clothing clothing = new Clothing();
			clothing.setName(name);
			clothing.setPurchasePrice(purchasePrice);
			clothing.setSalesPrice(salesPrice);
			clothing.setRentPrice(rentPrice);
			clothing.setCountryOfOrigin(countryOfOrigin);
			clothing.setMinStock(minStock);
			clothing.setMaxStock(maxStock);
			clothing.setCurrentStock(currentStock);
			clothing.setSupplier(dbSup.findSupplier(supplierID, true));
			clothing.setSize(variable1);
			clothing.setColour(variable2);
			dbClo.insertClothing(clothing);
		}
		if(productType.equals("Equipment"))
		{
			IFDBEquipment dbEquip = new DBEquipment();
			Equipment equipment = new Equipment();
			equipment.setName(name);
			equipment.setPurchasePrice(purchasePrice);
			equipment.setSalesPrice(salesPrice);
			equipment.setRentPrice(rentPrice);
			equipment.setCountryOfOrigin(countryOfOrigin);
			equipment.setMinStock(minStock);
			equipment.setMaxStock(maxStock);
			equipment.setCurrentStock(currentStock);
			equipment.setType(variable1);
			equipment.setDescription(variable2);
			dbEquip.insertEquipment(equipment);
		}
		if(productType.equals("Gun Replicas"))
		{
			IFDBGunReplicas dbGun = new DBGunReplicas();
			GunReplicas gunRep = new GunReplicas();
			gunRep.setName(name);
			gunRep.setPurchasePrice(purchasePrice);
			gunRep.setSalesPrice(salesPrice);
			gunRep.setRentPrice(rentPrice);
			gunRep.setCountryOfOrigin(countryOfOrigin);
			gunRep.setMinStock(minStock);
			gunRep.setMaxStock(maxStock);
			gunRep.setCurrentStock(currentStock);
			gunRep.setFabric(variable1);
			gunRep.setCalibre(variable2);
			dbGun.insertGunReplica(gunRep);
	}
	}

	public void deleteProduct(String barcode, String productType)
    {
		if(productType.equals("Clothing"))
		{
			IFDBClothing dbClo = new DBClothing();
			dbClo.deleteClothing(barcode);
		}
		if(productType.equals("Equipment"))
		{
			IFDBEquipment dbEquip = new DBEquipment();
			dbEquip.deleteEquipment(barcode);
		}
		if(productType.equals("Gun Replicas"))
		{
			IFDBGunReplicas dbGun = new DBGunReplicas();
			dbGun.deleteGunReplica(barcode);
		}
    }

}
